//
//  SIXWeatherView.m
//  FastDoctor_6
//
//  Created by cool on 16/3/1.
//  Copyright © 2016年 cool. All rights reserved.
//
#define themeColor [UIColor colorWithRed:51 / 255.0 green:188 / 255.0 blue:183 / 255.0 alpha:1.0]
#define ScreenW [UIScreen mainScreen].bounds.size.width
#define WeahterViewH self.bounds.size.height


#import "SIXWeatherView.h"

@interface SIXWeatherView()
@property (nonatomic, strong) UIView *seperatorView; //分割线
@property (nonatomic, strong) UIImageView *weatherImageView;//天气图片
@property (nonatomic, strong) UILabel *weatherLabel;//晴,阴,多云
@property (nonatomic, strong) UILabel *temperatureLabel;//温度图片
@property (nonatomic, strong) UILabel *dateLabel;//日期


@end

@implementation SIXWeatherView

- (instancetype)initWithFrame:(CGRect)frame
{
    if ([super initWithFrame:frame]) {
        //添加控件
        [self addSubviews];
    }
    
    return self;
}

- (void)addSubviews{
    
    self.backgroundColor = [UIColor colorWithRed:244/255.0 green:244/255.0 blue:248/255.0 alpha:1];
    //天气图片
    UIImageView *weatherImageView = [[UIImageView alloc] init];
    self.weatherImageView = weatherImageView;
    
    weatherImageView.image = [UIImage imageNamed:@"sun"];
    
    [self addSubview:weatherImageView];
    
    //天气label
    UILabel *label = [[UILabel alloc] init];
    self.weatherLabel = label;
    
    label.font = [UIFont systemFontOfSize: 16];
    
    label.textColor = themeColor;
    
    label.textAlignment = NSTextAlignmentCenter;
    
    label.numberOfLines = 0;
    
    label.text = @"晴";
    
    [self addSubview:label];
    
    //地区
    UIButton *placeBtn = [[UIButton alloc] init];
    
    self.placeBtn = placeBtn;
    
    [self.placeBtn setTitle:@"北京市" forState:UIControlStateNormal];
    
    [self.placeBtn setTitleColor:themeColor forState:UIControlStateNormal];
    
    //按钮的点击事件
    [self.placeBtn addTarget:self action:@selector(changePlace) forControlEvents:UIControlEventTouchUpInside];
    
    [self addSubview:placeBtn];
    
    //分割线
    UIView *seperatorView = [[UIView alloc] init];
    
    self.seperatorView = seperatorView;
    
    seperatorView.backgroundColor = [UIColor grayColor];
    
    [self addSubview:seperatorView];
    
    //天气详情
    //温度
    UILabel *temperatureLabel = [[UILabel alloc] init];
    
    temperatureLabel.textColor = themeColor;
    
    temperatureLabel.textAlignment = NSTextAlignmentCenter;
    
    temperatureLabel.font = [UIFont systemFontOfSize:16];
    
    temperatureLabel.text = [NSString stringWithFormat:@"温度: 10 ~ -2℃"];

    
    self.temperatureLabel = temperatureLabel;
    
    [self addSubview:temperatureLabel];
    
    //日期
    
    UILabel *dateLabel = [[UILabel alloc] init];
    
    dateLabel.textColor = themeColor;
    
    dateLabel.textAlignment = NSTextAlignmentCenter;
    
    self.dateLabel = dateLabel;
    
    dateLabel.text = [NSString stringWithFormat:@"2016年03月01日"];
    
    [self addSubview:dateLabel];
    
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    self.weatherImageView.frame = CGRectMake(ScreenW * 0.125 * 0.2, WeahterViewH * 0.2, WeahterViewH * 0.6, WeahterViewH * 0.6);
    
    self.weatherLabel.frame = CGRectMake(ScreenW * 0.125, 0, ScreenW * 0.125 ,WeahterViewH);
    
    self.placeBtn.frame = CGRectMake(ScreenW * 0.25, 0, ScreenW * 0.25, WeahterViewH);
    self.seperatorView.frame = CGRectMake(ScreenW * 0.5, 10, 0.5, WeahterViewH-20);
    self.temperatureLabel.frame = CGRectMake(ScreenW * 0.5 + 1, 1, ScreenW * 0.5 - 1, WeahterViewH * 0.5);
    self.dateLabel.frame = CGRectMake(ScreenW * 0.5 + 1, WeahterViewH * 0.5-1,ScreenW * 0.5 - 1, WeahterViewH * 0.5);
    
}

- (void)changePlace{
    if ([self.delegate respondsToSelector:@selector(placeBtnClickWith:)]) {
        [self.delegate placeBtnClickWith:self];
    }
    
}

@end
